
package com.wyzz.hr.action;

import java.util.Date;
import java.util.List;
import org.apache.axis.utils.StringUtils;

import com.wyzz.hr.base.BaseAction;
import com.wyzz.hr.bo.IBenefitTypeBO;
import com.wyzz.hr.bo.IEmpTypeBO;
import com.wyzz.hr.bo.ILocationBO;
import com.wyzz.hr.bo.IPositionBo;
import com.wyzz.hr.bo.IRecruitapplierBo;
import com.wyzz.hr.pojo.Employee;
import com.wyzz.hr.pojo.Position;
import com.wyzz.hr.pojo.Recruitapplier;
import com.wyzz.hr.spring.SpringBeanFactory;
import com.wyzz.hr.util.DatabaseSysConfigManager;
import com.wyzz.hr.util.StringUtil;
import com.wyzz.hr.util.SysConfigManager;

public class AddApplierToUser extends BaseAction {

	public AddApplierToUser() {
		dbConfigManager = DatabaseSysConfigManager.getInstance();
	}

	public String execute() {
		if (StringUtils.isEmpty(applierId)) {
			addActionError("\u53C2\u6570\u9519\u8BEF\uFF0C\u8BF7\u5237\u65B0\u540E\u91CD\u8BD5\uFF01");
			return "input";
		}
		IEmpTypeBO bo = (IEmpTypeBO) SpringBeanFactory.getBean("emptypeBO");
		empTypes = bo.FindEnabledEmpType();
		ILocationBO localbo = (ILocationBO) SpringBeanFactory
				.getBean("locationBO");
		locations = localbo.FindEnabledLocation();
		localbo = null;
		IBenefitTypeBO benefitTypeBo = (IBenefitTypeBO) SpringBeanFactory
				.getBean("benefitTypeBo");
		benefitTypes = benefitTypeBo.findAll();
		exShiftEnable = dbConfigManager.getProperty("sys.examin.shift.enable")
				.trim();
		IRecruitapplierBo applierBo = (IRecruitapplierBo) getBean("applierBo");
		Recruitapplier applier = applierBo.loadApplierById(applierId);
		if (emp == null)
			emp = new Employee();
		IPositionBo posBo = (IPositionBo) SpringBeanFactory
				.getBean("positionBo");
		Position pos = null;
		if (applier.getRecaPlanId() != null
				&& applier.getRecaPlanId().getRecpPbNo() != null) {
			pos = posBo.getPositionByPbId(applier.getRecaPlanId().getRecpPbNo()
					.getId());
			emp.setPosition(pos);
			emp.setEmpPbNo(applier.getRecaPlanId().getRecpPbNo());
			emp.setEmpDeptNo(applier.getRecaPlanId().getRecpDepartmentNo());
			emp.setEmpType(applier.getRecaPlanId().getRecpType());
			emp.setEmpLocationNo(applier.getRecaPlanId().getRecpWorkLocation());
		}
		emp.setEmpName(applier.getRecaName());
		emp.setEmpSpeciality(applier.getRecaSpeciality());
		emp.setEmpJoinDate(new Date());
		if (StringUtil.isMobile(applier.getRecaPhone()))
			emp.setEmpMobile(applier.getRecaPhone());
		else
			emp.setEmpHomePhone(applier.getRecaPhone());
		emp.setEmpEmail(applier.getRecaEmail());
		emp.setEmpDiploma(applier.getRecaDiploma());
		emp.setEmpSchool(applier.getRecaSchool());
		emp.setEmpBirthDate(applier.getRecaBirthDate());
		emp.setEmpCurrAddr(applier.getRecaCurrAddr());
		emp.setEmpCurrZip(applier.getRecaCurrZip());
		emp.setEmpGender(applier.getRecaGender());
		emp.setEmpResidenceLoc(applier.getRecaResidenceLoc());
		return "success";
	}

	public Employee getEmp() {
		return emp;
	}

	public void setEmp(Employee emp) {
		this.emp = emp;
	}

	public String getApplierId() {
		return applierId;
	}

	public void setApplierId(String applierId) {
		this.applierId = applierId;
	}

	public List getLocations() {
		return locations;
	}

	public void setLocations(List locations) {
		this.locations = locations;
	}

	public List getEmpTypes() {
		return empTypes;
	}

	public void setEmpTypes(List empTypes) {
		this.empTypes = empTypes;
	}

	public List getBenefitTypes() {
		return benefitTypes;
	}

	public void setBenefitTypes(List benefitTypes) {
		this.benefitTypes = benefitTypes;
	}

	public String getExShiftEnable() {
		return exShiftEnable;
	}

	public void setExShiftEnable(String exShiftEnable) {
		this.exShiftEnable = exShiftEnable;
	}

	private Employee emp;
	private String applierId;
	SysConfigManager dbConfigManager;
	private List locations;
	private List empTypes;
	private List benefitTypes;
	String exShiftEnable;
}
